﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyCommunity.Models;
using System.Web.Security;
using MyCommunity.DataAccess;

public class UserEventAttendanceDAL : IUserEventAttendanceDAL
{
    //datacontext for entity framework
    private readonly MyCommunityDataContext _db;

    public UserEventAttendanceDAL()
    {
        _db = new MyCommunityDataContext();
    }

    public UserEventAttendance GetUserEvent(int eventId, int userId)
    {
        return _db.UserEventAttendance.FirstOrDefault(i => i.EventId == eventId &&  i.UserId == userId);
    }

    public UserEventAttendance GetSingleEvent(int eventId)
    {
        return _db.UserEventAttendance.FirstOrDefault(i => i.EventId == eventId);
    }

    public List<UserEventAttendance> GetAllUsersForEvent(int eventId)
    {
        return _db.UserEventAttendance.Where(i => i.EventId == eventId).ToList();
    }

    public List<UserEventAttendance> GetAllUserEvents(int userId)
    {
        return _db.UserEventAttendance.Where(i => i.UserId == userId).ToList();
    }

    public void RegisterUser(UserEventAttendance userEvent)
    {
        _db.UserEventAttendance.InsertOnSubmit(userEvent);
    }
   
    public void Save()
    {
        _db.SubmitChanges();
    }
}